package com.yaozheng.vocationaltraining.view;

import net.sf.json.JSONObject;

import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById;

import android.content.Context;
import android.content.Intent;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yaozheng.vocationaltraining.R;
import com.yaozheng.vocationaltraining.utils.BitmapLoader;
import com.yaozheng.vocationaltraining.utils.Constants;
import com.yaozheng.vocationaltraining.utils.TypeUtils;

@EViewGroup(R.layout.item_news)
public class NewsListItemView extends LinearLayout {
	@ViewById
	TextView newsTitleText, newsContentText;
	@ViewById
	ImageView newsContentImage;


	public NewsListItemView(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
	}

	public NewsListItemView(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}

	@Click(R.id.itemRootView)
	public void enterNewsDetail() {
		Intent intent = new Intent();
		intent.setClassName(getContext(),
				Constants.NEWSDETAILACTIVITY_CLASS_NAME);
		intent.putExtra("title", "宝沃新闻");
		getContext().startActivity(intent);
	}

	/**
	 * 加载数据
	 * 
	 * @param newseJsonObject
	 */
	public void loadData(JSONObject newseJsonObject, BitmapLoader bitmapLoader) {
		newsTitleText.setText(TypeUtils.getJsonString(newseJsonObject,
				"subject", ""));
		newsContentText.setText(TypeUtils.getJsonString(newseJsonObject,
				"desc", ""));

		// ImageLoader.getInstance().displayImage(
		// TypeUtils.getJsonString(newseJsonObject, "image"),
		// newsContentImage, options);
		bitmapLoader.displayImage(
				TypeUtils.getJsonString(newseJsonObject, "image"),
				newsContentImage);

	}
}
